package ballParadigm;

public class collusion {
	public boolean collide(GameObjects someobject, Ball ball){
		if(((ball.x+ball.WIDTH)>someobject.x)&&((ball.x+ball.WIDTH)<(someobject.x+someobject.WIDTH))){//Right is inside
				if(((ball.y+ball.HEIGHT)>someobject.y)&&((ball.y+ball.HEIGHT)<(someobject.y+someobject.HEIGHT)))//Bottom-right is inside
					return true;
				else if(((ball.y+ball.HEIGHT)>(someobject.y+someobject.HEIGHT))&&(ball.y<someobject.y))//Right edge inside
					return true;
				else if((ball.y>someobject.y)&&(ball.y<(someobject.y+someobject.HEIGHT)))//Top-right is inside
					return true;
		} else if((ball.x>someobject.x)&&(ball.x<(someobject.x+someobject.WIDTH))){//Left is inside
			if(((ball.y+ball.HEIGHT)>someobject.y)&&((ball.y+ball.HEIGHT)<(someobject.y+someobject.HEIGHT)))//Bottom-left is inside
				return true;
			else if(((ball.y+ball.HEIGHT)>(someobject.y+someobject.HEIGHT))&&(ball.y<=someobject.y))//Left edge inside
				return true;
			else if((ball.y>someobject.y)&&(ball.y<(someobject.y+someobject.HEIGHT)))//Top-left is inside
				return true;
		}else if((ball.x<someobject.x)&&((ball.x+ball.WIDTH)>(someobject.x+someobject.WIDTH))){//Horizontally object is inside ball
			if((ball.y>someobject.y)&&(ball.y<someobject.y+someobject.HEIGHT))//If top edge is inside
				return true;
			else if(((ball.y+ball.HEIGHT)>someobject.y)&&((ball.y+ball.HEIGHT)<someobject.y+someobject.HEIGHT))//If bottom edge is inside
				return true;
		}
			
		return false;
	}
	public int collusionSide(GameObjects someobject, Ball ball){
		if(ball.velocityx==0){//Vertical movement of ball
			if(ball.velocityy>0)//Vertical down movement
				return 1;
			else//Vertical up movement
				return 5;
		}else if(ball.velocityy==0){//Horizontal movement of ball
			if(ball.velocityx>0)//Right movement
				return 7;
			else//Left movement
				return 3;
		}else{//Or else
			if(ball.velocityx>0){//Horizontally towards right
				if(ball.velocityy>0){//Towards down-right
					if((ball.prevy+ball.HEIGHT)>someobject.y)//First left of the object and ball collides
						return 7;
					else if((ball.prevx+ball.WIDTH)>someobject.x)//First top of the object and ball collides
						return 1;
					else if(((ball.prevx+ball.WIDTH)==someobject.x)&&((ball.prevy+ball.HEIGHT)==someobject.y))//First the top-left corner of the object and ball collides
						return 8;
					else if((someobject.x-(ball.prevx+ball.WIDTH)-ball.velocityx)>(someobject.y-(ball.prevy+ball.HEIGHT)-ball.velocityy))//First top of the object and ball collides
						return 1;
					else if((someobject.x-(ball.prevx+ball.WIDTH)-ball.velocityx)==(someobject.y-(ball.prevy+ball.HEIGHT)-ball.velocityy))//First the top-left corner of the object and ball collides
						return 8;
					else//First the left of the object and ball collides
						return 7;
				}else if(ball.velocityy<0){//Towards up-right
					if(ball.prevy<(someobject.y+someobject.HEIGHT))//First left of the object and ball collides
						return 7;
					else if((ball.prevx+ball.WIDTH)>someobject.x)//First bottom of the object and ball collides
						return 5;
					else if(((ball.prevx+ball.WIDTH)==someobject.x)&&(ball.prevy==(someobject.y+someobject.HEIGHT)))//First the bottom-left corner of the object and ball collides
						return 8;
					else if((someobject.x-(ball.prevx+ball.WIDTH)-ball.velocityx)>(ball.prevy-(someobject.y+someobject.HEIGHT)+ball.velocityy))//First bottom of the object and ball collides
						return 5;
					else if((someobject.x-(ball.prevx+ball.WIDTH)-ball.velocityx)==(ball.prevy-(someobject.y+someobject.HEIGHT)+ball.velocityy))//First the bottom-left corner of the object and ball collides
						return 6;
					else//First the left of the object and ball collides
						return 7;
				}
			}else if(ball.velocityx<0){//Horizontally towards left
				if(ball.velocityy>0){//Towards down-left
					if((ball.prevy+ball.HEIGHT)>someobject.y)//First right of the object and ball collides
						return 3;
					else if(ball.prevx<(someobject.x+someobject.WIDTH))//First top of the object and ball collides
						return 1;
					else if((ball.prevx==(someobject.x+someobject.WIDTH))&&((ball.prevy+ball.HEIGHT)==(someobject.y)))//First the top-right corner of the object and ball collides
						return 2;
					else if((ball.prevx-(someobject.x+someobject.WIDTH)+ball.velocityx)>(someobject.y-(ball.prevy+ball.HEIGHT)-ball.velocityy))//First top of the object and ball collides
						return 1;
					else if((ball.prevx-(someobject.x+someobject.WIDTH)+ball.velocityx)==(someobject.y-(ball.prevy+ball.HEIGHT)-ball.velocityy))//First the top-right corner of the object and ball collides
						return 2;
					else//First the right of the object and ball collides
						return 3;
				}else if(ball.velocityy<0){//Towards up-left
					if(ball.prevy<(someobject.y+someobject.HEIGHT))//First right of the object and ball collides
						return 3;
					else if(ball.prevx<(someobject.x+someobject.WIDTH))//First bottom of the object and ball collides
						return 5;
					else if((ball.prevx==(someobject.x+someobject.WIDTH))&&(ball.prevy==(someobject.y+someobject.HEIGHT)))//First the bottom-right corner of the object and ball collides
						return 2;
					else if((ball.prevx-(someobject.x+someobject.WIDTH)+ball.velocityx)>(ball.prevy-(someobject.y+someobject.HEIGHT)+ball.velocityy))//First bottom of the object and ball collides
						return 5;
					else if((ball.prevx-(someobject.x+someobject.WIDTH)+ball.velocityx)==(ball.prevy-(someobject.y+someobject.HEIGHT)+ball.velocityy))//First the bottom-right corner of the object and ball collides
						return 4;
					else//First the right of the object and ball collides
						return 3;
				}
			}
		}
		return -10;
	}
}
